﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoatNGoat.Input.ImpulseLayer;
using SharpDX;
using SharpDX.DirectInput;

namespace BoatNGoat.Input
{
    public class InputManager
    {
        // May need to keep this for reacquisition.
        private DirectInput _input;
        private ImpulseMapper _impulseMapper;
        private LocalSimulation _simulation;

        private IEnumerable<string> _currentImpulses;
        private static Dictionary<string, Action> _impulseActions = new Dictionary<string, Action>();

        public InputManager(DirectInput input, LocalSimulation simulation)
        {
            _input = input;
            _simulation = simulation;
            _impulseMapper = new ImpulseMapper(input);
        }

        public static void RegisterImpulseAction(string impulse, Action action)
        {
            _impulseActions.Add(impulse, action);
        }

        public void HandleInput()
        {
            GetImpulses();

            // Invoke any Actions that these Impulses map to.
            foreach (string impulse in _currentImpulses)
            {
                if (_impulseActions.ContainsKey(impulse))
                    _impulseActions[impulse].Invoke();
            }
        }

        private void GetImpulses()
        {
            _currentImpulses = _impulseMapper.GetImpulses();
        }
    }
}
